import 'package:flutter_vant/main.dart';
import 'package:flutter/material.dart';
import 'package:simulator/components/DemoView/style.dart';

class DemoView extends HookWidget {
  final String title;
  final List<Widget> children;
  final bool isGrid;
  const DemoView(
      {Key? key, this.title = '', this.children = const [], this.isGrid = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget renderTitle() {
      return Frame(
        styles: IDemoViewStyle.title,
        children: [TextView(title)],
      );
    }

    renderGrid() {
      return SizedBox(
        width: double.infinity,
        height: children.length > 3 ? 120.w : 60.w,
        child: GridView.count(
            physics: const NeverScrollableScrollPhysics(),
            crossAxisCount: 3,
            mainAxisSpacing: 10,
            crossAxisSpacing: 15,
            childAspectRatio: 2,
            children: children),
      );
    }

    List<Widget> widgets = [
      renderTitle(),
    ];
    if (isGrid == false) {
      widgets.addAll(children);
    } else {
      widgets.add(renderGrid());
    }
    return Frame(
      styles: IDemoViewStyle.main,
      children: widgets,
    );
  }
}
